package com.sgb.trip.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.sgb.trip.api.TripNet;
import com.sgb.trip.entity.FlightOrdersInfoEntity;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.base.model.entity.ListResponse;
import com.swgk.core.common.base.BaseViewModel;
import com.swgk.core.dialog.DialogHelper;

import java.util.List;
import java.util.Map;

/**
 * Time:2021/9/13
 * Author:黄淋
 * Description:
 */
public class FlightOrdersSelfModel extends BaseViewModel {
    public MutableLiveData<List<FlightOrdersInfoEntity>> ldOrdersData = new MutableLiveData<>();

    public FlightOrdersSelfModel(@NonNull Application application) {
        super(application);
    }
    private int pageNum = 1;
    /**
     * 加载机票订单数据
     */
    public void getFlightOrdersList(boolean isMore, Map<String, Object> map) {
        pageNum = isMore ? pageNum + 1 : 1;
        map.put("page", pageNum);
        map.put("limit", 10);

        TripNet.getInstance().getService().getOrderList(map).enqueue(new ICallBack<BaseEntity<ListResponse<List<FlightOrdersInfoEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<FlightOrdersInfoEntity>>> data) {
                DialogHelper.dismissProgressDialog();
                if (data == null || data.getState() == null || data.getData() == null) {
                    return;
                }

                if (data.getData() != null) {
                    ldOrdersData.postValue(data.getData().getList());
                }
            }

            @Override
            public void onFailureWithEntity(BaseEntity entity) {
                DialogHelper.dismissProgressDialog();
            }
        });


    }

}
